|
|
|
|
|
|
|
Private Sub cmdDrawWord_Click()
DrawTheObject MonthViewl.object
End Sub
Private Sub Command1_Click()
PrintTheObject MonthViewl.object
End Sub |
|
|
|
|
|
|
|
|
Now, you'll find that the two drawing commands work. But the MonthView control will not print. |
|
|
|
|
|
|
|
|
Telling Visual Basic to Print |
|
|
|
|
|
|
|
|
Let's take another look at the PrintTheObject function: |
|
|
|
|
|
|
|
|
Private Function PrintTheObject(obj As Object)
Dim r As RECT
Dim res As Long
Printer.ScaleMode = vbPixels
r.Right = Printer.ScaleWidth
r.Bottom = Printer.ScaleHeight
res = OleDraw(obj, Aspects(cmbAspect.ListIndex), Printer.hDC, r)
If res <> 0 Then
Err.Raise res
End If
Printer.EndDoc
End Function |
|
|
|
|
|
|
|
|
How does Visual Basic know that you are actually ready to print something? Setting the ScaleMode just lets VB know what scale mode to use once you start drawing into the printer object. The OleDraw command does dump data into the printer's device context, but this bypasses Visual Basic's drawing system, so VB has no way of knowing that you actually performed a drawing operation. Thus, when the EndDoc command occurs, Visual Basic looks and sees that nothing has been drawn, so it does nothing. |
|
|
|
|
|
|
|
|
It is necessary to trick Visual Basic into initializing the device context before calling the OleDraw function. This is done by changing the function to the following: |
|
|
|
|
|
|
|
|
Private Function PrintTheObject(obj As Object)
Dim r As RECT
Dim res As Long |
|
|
|
|
|